/* Siberian Olympiad. 2 stage.
  Problemset: http://agul-problems1.googlecode.com/svn/trunk/2010-2011/wso/stage2/wso_2stage.pdf
  Problem 3.
  Points: 100
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string.h>
#include <ctime>
using namespace std;
class longs {
	short chislo[1500];
	int l;
public:
	bool operator < (const longs num) const {
		int new_l=l, nnew_l=num.l;
		while (!chislo[new_l-1]) new_l--;
		while (!num.chislo[nnew_l-1]) nnew_l--;
		if (new_l!=nnew_l) return new_l<nnew_l;
		for (int i=l-1; i >= 0; i--)  {
			if (num.chislo[i]!=chislo[i]) return chislo[i]<num.chislo[i]; 
		}
		return 0;
	}
	bool operator <= (const longs num) const {
		if (l!=num.l) return l<num.l;
		for (int i=l-1; i>=0; i--) {
			if (num.chislo[i]!=chislo[i]) return chislo[i]<num.chislo[i];
		}
		return 1;
	}
	longs operator - (const longs num) const {
		longs *result=new longs();
		int pom=0,plus_v=0,next_pom=0;
		for (int i=0; i<l; i++) {
			if (chislo[i]-pom<num.getnum(i)) {
				next_pom=1;
				plus_v=10;
			} else {
				next_pom=0;
				plus_v=0;
			}
			result->plus(chislo[i]-pom+plus_v-num.getnum(i));
			pom=next_pom;

		}
		result->deletenil();
		return *result;
	}
	pair <longs,longs> operator / (const longs num) const {
			longs *result=new longs ();
			longs *cur=new longs();
			int i=l;
			while (true) {
				while (*cur<num && i>0) {
					i--;
					result->plus(0);
					cur->plus_end(chislo[i]);
				}
				int count=0;
				while (num<=*cur) {
					*cur=*cur-num;
					count++;
				}
				result->plus(count);
				if (i>0) cur->plus_end(chislo[--i]); 
				else {
					cur->deletenil();
					result->perevorot();
					result->deletenil();
					return pair<longs,longs> (*result,*cur);
				}
				cur->deletenil();
			}
	}
	void deletenil () {
		while (!chislo[l-1]) l--;
		if (l<0) l=0; 
	}
	void perevorot () {
		int n[1500];
		for (int i=0; i<l; i++) {
			n[l-i-1]=chislo[i];
		}
		for (int i=0; i<l; i++) {
			chislo[i]=n[i];
		}
	}

	longs () {l=0;}
	longs (char *s) {
		l=strlen(s);
		for (int i=0; i<l; i++) chislo[i]=s[l-i-1]-'0';
	}
	longs (short *num, int new_l) {
		l=new_l;
		for (int i=0; i<l; i++) chislo[i]=num[i];
	}
	void plus (short i) {
		chislo[l++]=i;
	}
	void plus_end(short i) {
		for (int j=l; j>0; j--) {
			chislo[j]=chislo[j-1];
		}
		chislo[0]=i;
		l++;
	}
	short getnum (int i) const {
		if (i>=l) return 0;
		return chislo[i];
	}
	void print () const {
		for (int i=l-1; i >= 0; i--) printf("%d",chislo[i]);
		if (l==0) printf("0");
	  printf("\n");
	}
	int to_num () {
		int n=0;
		for (int i=l-1; i >= 0; i--) n=n*10+chislo[i];
		return n;
	}
	longs (int n) {
		for (l=0; n; l++) {
			chislo[l]=n % 10;
			n /= 10;
		}
	}
};

int main () {
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	int n; 
	cin >> n;
	for (int i=0; i<n; i++) {
		char st[1500],st2[1500];
		scanf("%s%s",&st,&st2);
		longs l1 (st);
		longs l2 (st2);
		pair <longs,longs> result=l1 / l2;
		result.first.print();
		result.second.print();
	}
	return 0;
}
